<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>nest-learn documentation</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="icon" type="image/x-icon" href="../images/favicon.ico">
	   <link rel="stylesheet" href="../styles/style.css">
        <link rel="stylesheet" href="../styles/dark.css">
    </head>
    <body>
          <script>
               // Blocking script to avoid flickering dark mode
               // Dark mode toggle button
               var useDark = window.matchMedia('(prefers-color-scheme: dark)');
               var darkModeState = useDark.matches;
               var $darkModeToggleSwitchers = document.querySelectorAll('.dark-mode-switch input');
               var $darkModeToggles = document.querySelectorAll('.dark-mode-switch');
               var darkModeStateLocal = localStorage.getItem('compodoc_darkmode-state');

               function checkToggle(check) {
                    for (var i = 0; i < $darkModeToggleSwitchers.length; i++) {
                         $darkModeToggleSwitchers[i].checked = check;
                    }
               }

               function toggleDarkMode(state) {
                    if (window.localStorage) {
                         localStorage.setItem('compodoc_darkmode-state', state);
                    }

                    checkToggle(state);

                    const hasClass = document.body.classList.contains('dark');

                    if (state) {
                         for (var i = 0; i < $darkModeToggles.length; i++) {
                              $darkModeToggles[i].classList.add('dark');
                         }
                         if (!hasClass) {
                              document.body.classList.add('dark');
                         }
                    } else {
                         for (var i = 0; i < $darkModeToggles.length; i++) {
                              $darkModeToggles[i].classList.remove('dark');
                         }
                         if (hasClass) {
                              document.body.classList.remove('dark');
                         }
                    }
               }

               useDark.addEventListener('change', function (evt) {
                    toggleDarkMode(evt.matches);
               });
               if (darkModeStateLocal) {
                    darkModeState = darkModeStateLocal === 'true';
               }
               toggleDarkMode(darkModeState);
          </script>

        <div class="navbar navbar-default navbar-fixed-top d-md-none p-0">
               <div class="d-flex">
                    <a href="../" class="navbar-brand">nest-learn documentation</a>
                    <button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
               </div>
        </div>

        <div class="xs-menu menu" id="mobile-menu">
                <div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div>            <compodoc-menu></compodoc-menu>
        </div>

        <div class="container-fluid main">
           <div class="row main">
               <div class="d-none d-md-block menu">
                   <compodoc-menu mode="normal"></compodoc-menu>
               </div>
               <!-- START CONTENT -->
               <div class="content injectable">
                   <div class="content-data">








<ol class="breadcrumb">
  <li class="breadcrumb-item">Injectables</li>
  <li class="breadcrumb-item" >LoginUserService</li>
</ol>

<ul class="nav nav-tabs" role="tablist">
        <li class="nav-item">
            <a href="#info" 
                class="nav-link"
                class="nav-link active"
                role="tab" id="info-tab" data-bs-toggle="tab" data-link="info">Info</a>
        </li>
        <li class="nav-item">
            <a href="#source" 
                class="nav-link"
                
                role="tab" id="source-tab" data-bs-toggle="tab" data-link="source">Source</a>
        </li>
</ul>

<div class="tab-content">
    <div class="tab-pane fade active in" id="info">
        <p class="comment">
            <h3>File</h3>
        </p>
        <p class="comment">
            <code>src/login-user/login-user.service.ts</code>
        </p>





            <section data-compodoc="block-index">
    <h3 id="index">Index</h3>
    <table class="table table-sm table-bordered index-table">
        <tbody>
                <tr>
                    <td class="col-md-4">
                        <h6><b>Properties</b></h6>
                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <ul class="index-list">
                            <li>
                                    <span class="modifier"></span>
                                <a href="#entityManager" >entityManager</a>
                            </li>
                            <li>
                                    <span class="modifier">Private</span>
                                <a href="#logger" >logger</a>
                            </li>
                            <li>
                                    <span class="modifier"></span>
                                    <span class="modifier">Private</span>
                                <a href="#loginUserRepository" >loginUserRepository</a>
                            </li>
                        </ul>
                    </td>
                </tr>

                <tr>
                    <td class="col-md-4">
                        <h6><b>Methods</b></h6>
                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <ul class="index-list">
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#findByUserId" >findByUserId</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#findByUsername" >findByUsername</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#findGoogleUserByEmail" >findGoogleUserByEmail</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#findOneByUsername" >findOneByUsername</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#initData" >initData</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#login" >login</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#login2" >login2</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#register" >register</a>
                            </li>
                            <li>
                                    <span class="modifier">Async</span>
                                <a href="#registerByGithubInfo" >registerByGithubInfo</a>
                            </li>
                        </ul>
                    </td>
                </tr>





        </tbody>
    </table>
</section>


            <section data-compodoc="block-methods">
    
    <h3 id="methods">
        Methods
    </h3>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="findByUserId"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>findByUserId</b></span>
                        <a href="#findByUserId"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>findByUserId(userId: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank">number</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="116"
                                    class="link-to-prism">src/login-user/login-user.service.ts:116</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>userId</td>
                                            <td>
                                                            <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="findByUsername"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>findByUsername</b></span>
                        <a href="#findByUsername"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>findByUsername(username: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="104"
                                    class="link-to-prism">src/login-user/login-user.service.ts:104</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>username</td>
                                            <td>
                                                            <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="findGoogleUserByEmail"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>findGoogleUserByEmail</b></span>
                        <a href="#findGoogleUserByEmail"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>findGoogleUserByEmail(email: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="179"
                                    class="link-to-prism">src/login-user/login-user.service.ts:179</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>email</td>
                                            <td>
                                                            <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="findOneByUsername"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>findOneByUsername</b></span>
                        <a href="#findOneByUsername"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>findOneByUsername(username: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="91"
                                    class="link-to-prism">src/login-user/login-user.service.ts:91</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>username</td>
                                            <td>
                                                            <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="initData"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>initData</b></span>
                        <a href="#initData"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>initData()</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="35"
                                    class="link-to-prism">src/login-user/login-user.service.ts:35</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                        <div class="io-description">
                            <b>Returns : </b>        <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >any</a></code>

                        </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="login"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>login</b></span>
                        <a href="#login"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>login(user: <a href="../classes/LoginDto.html" target="_self">LoginDto</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="124"
                                    class="link-to-prism">src/login-user/login-user.service.ts:124</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>user</td>
                                            <td>
                                                            <code><a href="../classes/LoginDto.html" target="_self" >LoginDto</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="login2"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>login2</b></span>
                        <a href="#login2"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>login2(user: <a href="../classes/LoginDto.html" target="_self">LoginDto</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="136"
                                    class="link-to-prism">src/login-user/login-user.service.ts:136</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>user</td>
                                            <td>
                                                            <code><a href="../classes/LoginDto.html" target="_self" >LoginDto</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="register"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>register</b></span>
                        <a href="#register"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>register(user: <a href="../classes/RegisterDto.html" target="_self">RegisterDto</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="149"
                                    class="link-to-prism">src/login-user/login-user.service.ts:149</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>user</td>
                                            <td>
                                                            <code><a href="../classes/RegisterDto.html" target="_self" >RegisterDto</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="registerByGithubInfo"></a>
                    <span class="name">
                            <span class="modifier">Async</span>
                        <span ><b>registerByGithubInfo</b></span>
                        <a href="#registerByGithubInfo"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="col-md-4">
                        <span class="modifier-icon icon ion-ios-reset"></span>
                    <code>registerByGithubInfo(info: <a href="../interfaces/GoogleInfo.html" target="_self">GoogleInfo</a>)</code>
                </td>
            </tr>


                    <tr>
                        <td class="col-md-4">
                            <div class="io-line">Defined in <a href="" data-line="167"
                                    class="link-to-prism">src/login-user/login-user.service.ts:167</a></div>
                        </td>
                    </tr>


            <tr>
                <td class="col-md-4">

                            <div class="io-description">
                                <b>Parameters :</b>
                                
                                <table class="params">
                                    <thead>
                                        <tr>
                                            <td>Name</td>
                                                <td>Type</td>
                                            <td>Optional</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                                <td>info</td>
                                            <td>
                                                            <code><a href="../interfaces/GoogleInfo.html" target="_self" >GoogleInfo</a></code>
                                            </td>

                                            <td>
                                                    No
                                            </td>


                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        <div class="io-description">
                            <b>Returns : </b>    <code>unknown</code>

                        </div>
                            <div class="io-description">
                                
                            </div>
                </td>
            </tr>
        </tbody>
    </table>
</section>
            <section data-compodoc="block-properties">
    
    <h3 id="inputs">
        Properties
    </h3>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="entityManager"></a>
                    <span class="name">
                            <span class="modifier"></span>
                        <span ><b>entityManager</b></span>
                        <a href="#entityManager"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>    <code>EntityManager</code>

                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <b>Decorators : </b>
                        <br />
                        <code>
                            @InjectEntityManager()<br />
                        </code>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="33" class="link-to-prism">src/login-user/login-user.service.ts:33</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="logger"></a>
                    <span class="name">
                            <span class="modifier">Private</span>
                        <span ><b>logger</b></span>
                        <a href="#logger"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Default value : </i><code>new Logger()</code>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="27" class="link-to-prism">src/login-user/login-user.service.ts:27</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="loginUserRepository"></a>
                    <span class="name">
                            <span class="modifier"></span>
                            <span class="modifier">Private</span>
                        <span ><b>loginUserRepository</b></span>
                        <a href="#loginUserRepository"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>    <code>Repository&lt;LoginUser&gt;</code>

                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <b>Decorators : </b>
                        <br />
                        <code>
                            @InjectRepository(LoginUser)<br />
                        </code>
                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="30" class="link-to-prism">src/login-user/login-user.service.ts:30</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
</section>

    </div>


    <div class="tab-pane fade  tab-source-code" id="source">
        <pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { HttpException, HttpStatus, Injectable, Post } from &#x27;@nestjs/common&#x27;;
import { CreateLoginUserDto } from &#x27;./dto/create-login-user.dto&#x27;;
import { UpdateLoginUserDto } from &#x27;./dto/update-login-user.dto&#x27;;
import { EntityManager, Repository } from &#x27;typeorm&#x27;;
import { LoginUser } from &#x27;./entities/login-user.entity&#x27;;
import { InjectEntityManager, InjectRepository } from &#x27;@nestjs/typeorm&#x27;;
import { Logger } from &#x27;winston&#x27;;
import { RegisterDto } from &#x27;./dto/register.dto&#x27;;
import * as crypto from &#x27;crypto&#x27;;
import { LoginDto } from &#x27;./dto/login.dto&#x27;;
import { Permission } from &#x27;./entities/permission.entity&#x27;;
import { GithubUser } from &#x27;./entities/github-user.entity&#x27;;
function md5(str) {
  const hash &#x3D; crypto.createHash(&#x27;md5&#x27;);
  hash.update(str);
  return hash.digest(&#x27;hex&#x27;);
}

export interface GoogleInfo {
  email: string,
  firstName: string,
  lastName: string,
  picture: string,
}
@Injectable()
export class LoginUserService {
  private logger &#x3D; new Logger();

  @InjectRepository(LoginUser)
  private loginUserRepository: Repository&lt;LoginUser&gt;;

  @InjectEntityManager()
  entityManager: EntityManager;

  async initData() {
    const permission1 &#x3D; new Permission();
    permission1.name &#x3D; &#x27;create_aaa&#x27;;
    permission1.desc &#x3D; &#x27;新增 aaa&#x27;;

    const permission2 &#x3D; new Permission();
    permission2.name &#x3D; &#x27;update_aaa&#x27;;
    permission2.desc &#x3D; &#x27;修改 aaa&#x27;;

    const permission3 &#x3D; new Permission();
    permission3.name &#x3D; &#x27;remove_aaa&#x27;;
    permission3.desc &#x3D; &#x27;删除 aaa&#x27;;

    const permission4 &#x3D; new Permission();
    permission4.name &#x3D; &#x27;query_aaa&#x27;;
    permission4.desc &#x3D; &#x27;查询 aaa&#x27;;

    const permission5 &#x3D; new Permission();
    permission5.name &#x3D; &#x27;create_bbb&#x27;;
    permission5.desc &#x3D; &#x27;新增 bbb&#x27;;

    const permission6 &#x3D; new Permission();
    permission6.name &#x3D; &#x27;update_bbb&#x27;;
    permission6.desc &#x3D; &#x27;修改 bbb&#x27;;

    const permission7 &#x3D; new Permission();
    permission7.name &#x3D; &#x27;remove_bbb&#x27;;
    permission7.desc &#x3D; &#x27;删除 bbb&#x27;;

    const permission8 &#x3D; new Permission();
    permission8.name &#x3D; &#x27;query_bbb&#x27;;
    permission8.desc &#x3D; &#x27;查询 bbb&#x27;;

    const user1 &#x3D; new LoginUser();
    user1.username &#x3D; &#x27;东东&#x27;;
    user1.password &#x3D; &#x27;aaaaaa&#x27;;
    user1.permissions &#x3D; [permission1, permission2, permission3, permission4];

    const user2 &#x3D; new LoginUser();
    user2.username &#x3D; &#x27;光光&#x27;;
    user2.password &#x3D; &#x27;bbbbbb&#x27;;
    user2.permissions &#x3D; [permission5, permission6, permission7, permission8];

    await this.entityManager.save([
      permission1,
      permission2,
      permission3,
      permission4,
      permission5,
      permission6,
      permission7,
      permission8,
    ]);
    await this.entityManager.save([user1, user2]);
  }

  async findOneByUsername(username: string) {
    const user &#x3D; await this.entityManager.findOne(LoginUser, {
      where: {
        username
      }
    })
    return {
      userId: user.id,
      username: user.username,
      password: user.password
    }
  }

  async findByUsername(username: string) {
    const user &#x3D; await this.entityManager.findOne(LoginUser, {
      where: {
        username
      },
      relations: {
        permissions: true
      }
    })
    return user
  }

  async findByUserId(userId: number) {
    const user &#x3D; await this.entityManager.findOne(LoginUser, {
      where: {
        id: userId
      }
    })
    return user
  }
  async login(user: LoginDto) {
    const foundUser &#x3D; await this.loginUserRepository.findOneBy({
      username: user.username,
    });
    if (!foundUser) {
      throw new HttpException(&#x27;用户名不存在&#x27;, 200);
    }
    if (foundUser.password !&#x3D;&#x3D; md5(user.password)) {
      throw new HttpException(&#x27;密码错误&#x27;, 200);
    }
    return foundUser;
  }
  async login2(user: LoginDto) {
    const foundUser &#x3D; await this.loginUserRepository.findOneBy({
      username: user.username,
    });
    if (!foundUser) {
      throw new HttpException(&#x27;用户名不存在&#x27;, HttpStatus.ACCEPTED);
    }
    if (foundUser.password !&#x3D;&#x3D; md5(user.password)) {
      throw new HttpException(&#x27;密码错误&#x27;, HttpStatus.ACCEPTED);
    }
    return foundUser;
  }

  async register(user: RegisterDto) {
    const foundUser &#x3D; await this.loginUserRepository.findOneBy({
      username: user.username,
    });
    if (foundUser) {
      throw new HttpException(&#x27;用户已存在&#x27;, 200);
    }
    const newUser &#x3D; new LoginUser();
    newUser.username &#x3D; user.username;
    newUser.password &#x3D; md5(user.password);
    try {
      await this.loginUserRepository.save(newUser);
      return &#x27;注册成功&#x27;;
    } catch (error) {
      this.logger.error(error);
      return &#x27;注册失败&#x27;;
    }
  }
  async registerByGithubInfo(info: GoogleInfo) {
    const user &#x3D; new GithubUser();

    user.nickName &#x3D; &#x60;${info.firstName}_${info.lastName}&#x60;;
    user.avater &#x3D; info.picture;
    user.email &#x3D; info.email;
    user.password &#x3D; &#x27;&#x27;;
    user.registerType &#x3D; 2;

    return this.entityManager.save(GithubUser, user);
  }

  async findGoogleUserByEmail(email: string) {
    return this.entityManager.findOneBy(GithubUser, {
      registerType: 2,
      email
    });
  }
}
</code></pre>
    </div>

</div>













                   </div><div class="search-results">
    <div class="has-results">
        <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
        <ul class="search-results-list"></ul>
    </div>
    <div class="no-results">
        <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
    </div>
</div>
</div>
               <!-- END CONTENT -->
           </div>
       </div>

          <label class="dark-mode-switch">
               <input type="checkbox">
               <span class="slider">
                    <svg class="slider-icon" viewBox="0 0 24 24" fill="none" height="20" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" width="20" xmlns="http://www.w3.org/2000/svg">
                    <path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"></path>
                    </svg>
               </span>
          </label>

       <script>
            var COMPODOC_CURRENT_PAGE_DEPTH = 1;
            var COMPODOC_CURRENT_PAGE_CONTEXT = 'injectable';
            var COMPODOC_CURRENT_PAGE_URL = 'LoginUserService.html';
            var MAX_SEARCH_RESULTS = 15;
       </script>

       <script>
               $darkModeToggleSwitchers = document.querySelectorAll('.dark-mode-switch input');
               checkToggle(darkModeState);
               if ($darkModeToggleSwitchers.length > 0) {
                    for (var i = 0; i < $darkModeToggleSwitchers.length; i++) {
                         $darkModeToggleSwitchers[i].addEventListener('change', function (event) {
                              darkModeState = !darkModeState;
                              toggleDarkMode(darkModeState);
                         });
                    }
               }
          </script>

       <script src="../js/libs/custom-elements.min.js"></script>
       <script src="../js/libs/lit-html.js"></script>

       <script src="../js/menu-wc.js" defer></script>
       <script nomodule src="../js/menu-wc_es5.js" defer></script>

       <script src="../js/libs/bootstrap-native.js"></script>

       <script src="../js/libs/es6-shim.min.js"></script>
       <script src="../js/libs/EventDispatcher.js"></script>
       <script src="../js/libs/promise.min.js"></script>
       <script src="../js/libs/zepto.min.js"></script>

       <script src="../js/compodoc.js"></script>

       <script src="../js/tabs.js"></script>
       <script src="../js/menu.js"></script>
       <script src="../js/libs/clipboard.min.js"></script>
       <script src="../js/libs/prism.js"></script>
       <script src="../js/sourceCode.js"></script>
          <script src="../js/search/search.js"></script>
          <script src="../js/search/lunr.min.js"></script>
          <script src="../js/search/search-lunr.js"></script>
          <script src="../js/search/search_index.js"></script>
       <script src="../js/lazy-load-graphs.js"></script>


    </body>
</html>
